﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using FJERP.Model;
using System.Data.SqlClient;

namespace FJERP.DAL
{
    public class DocumentDAL
    {
        SQLHelper helper = new SQLHelper();
        /// <summary>
        /// 添加商品损益
        /// </summary>
        /// <param name="P"></param>
        /// <param name="xml"></param>
        /// <returns></returns>
        public int Document_Add(Document P, string xml)
        {
            string str = "Document_ADD";
            SqlParameter[] par = new SqlParameter[] { 
           
                       new SqlParameter("@Document_Type_Name",P.Document_Type_Name),
                       new SqlParameter("@WareHose_Id",P.WareHose_Id),
                       new SqlParameter("@Document_Date",P.Document_Date),
                       new SqlParameter("@Employee_Id",P.Employee_Id),
                       new SqlParameter("@Document_Remark",P.Document_Remark),
                       new SqlParameter("@Document_num",P.Document_num),
                       new SqlParameter("@xml",xml),
           
           };
            return helper.ExecNonquery_Proc(str, par);
        }
        /// <summary>
        /// 显示商品信息
        /// </summary>
        /// <param name="Product_Modelspe"></param>
        /// <returns></returns>
        public DataTable Product_Sel(string Product_Name)
        {
            StringBuilder str = new StringBuilder();
            str.Append("Document_Sel");
            SqlParameter[] par = new SqlParameter[] { 
           
              new SqlParameter("@Product_Name",Product_Name),
           };
            return helper.ExecDataTable_Proc(str.ToString(), par);
        }
        /// <summary>
        /// 根据类型显示不同的信息
        /// </summary>
        /// <param name="Document_Type_Name"></param>
        /// <returns></returns>
        public List<Document> Document_Show(string Document_Type_Name)
        {
            string str = "select Document_Id,Document_Date,Document_num,Document_Type_Name,Document.WareHose_Id,WareHose_Name,Document.Employee_Id,Employee_Name,Document_Remark from Document inner join WareHose on Document.WareHose_Id=WareHose.WareHose_Id inner join Employee on Document.Employee_Id=Employee.Employee_Id Where Document_Type_Name='" + Document_Type_Name + "'";
            DataTable table = helper.ExecDataTable(str);
            List<Document> list = new List<Document>();
            foreach (DataRow item in table.Rows)
            {
                Document d = new Document();
                d.Document_Id = Convert.ToInt32(item["Document_Id"]);
                d.Document_Remark = item["Document_Remark"].ToString();
                d.Document_Type_Name = item["Document_Type_Name"].ToString();
                d.Employee_Id = Convert.ToInt32(item["Employee_Id"]);
                d.WareHose_Id = Convert.ToInt32(item["WareHose_Id"]);
                d.Document_Date = Convert.ToDateTime(item["Document_Date"]);
                d.WareHose_Name = item["WareHose_Name"].ToString();
                d.Employee_Name = item["Employee_Name"].ToString();
                d.Document_num = item["Document_num"].ToString();
                list.Add(d);
            }
            return list;
        }
        /// <summary>
        /// 根据类型显示不同的商品信息
        /// </summary>
        /// <param name="Document_Type_Name"></param>
        /// <returns></returns>
        public List<Document_Mate> Document_Show_Pro(string Document_Type_Name)
        {
            string str = "select Document_Mate_Id,Document_Type_Name,Document_Mate.Document_Id,Document_Mate.Product_Id,Document_Mate_Num,Document_Mate_Price,Document_Mate_SumPrice,Product_Name,Product_Unit_Id,Product_Modelspe,Document_Remark from Document_Mate inner join Document on Document_Mate.Document_Id=Document.Document_Id inner join Product on Document_Mate.Product_Id=Product.Product_Id Where Document_Type_Name='" + Document_Type_Name + "'";
            DataTable table = helper.ExecDataTable(str);
            List<Document_Mate> list = new List<Document_Mate>();
            foreach (DataRow item in table.Rows)
            {
                Document_Mate d = new Document_Mate();
                d.Document_Id = Convert.ToInt32(item["Document_Id"]);
                d.Document_Remark = item["Document_Remark"].ToString();
                d.Document_Type_Name = item["Document_Type_Name"].ToString();
                d.Document_Mate_Id = Convert.ToInt32(item["Document_Mate_Id"]);
                d.Document_Mate_Num = Convert.ToInt32(item["Document_Mate_Num"]);
                d.Document_Mate_Price = Convert.ToDecimal(item["Document_Mate_Price"]);
                d.Document_Mate_SumPrice = Convert.ToDecimal(item["Document_Mate_SumPrice"]);
                d.Product_Id = Convert.ToInt32(item["Product_Id"]);
                d.Product_Modelspe = item["Product_Modelspe"].ToString();
                d.Product_Name = item["Product_Name"].ToString();
                d.Product_Unit_Id = item["Product_Unit_Id"].ToString();

                list.Add(d);
            }
            return list;
        }
        /// <summary>
        /// 根据类型显示不同的信息
        /// </summary>
        /// <param name="Document_Type_Name"></param>
        /// <returns></returns>
        public List<Document> Document_Show_List(string Document_Type_Name)
        {
            string str = "select Document_Date,Document.Document_Id,Document_num,Document_Mate.Product_Id,Product_Name,Document_Mate_Num,WareHose_Name,Employee_Name,Document_Remark from Document inner join WareHose on Document.WareHose_Id=WareHose.WareHose_Id inner join Employee on Document.Employee_Id=Employee.Employee_Id inner join Document_Mate on Document.Document_Id=Document_Mate.Document_Id inner join Product on Document_Mate.Product_Id=Product.Product_Id where Document_Type_Name='" + Document_Type_Name + "'";
            DataTable table = helper.ExecDataTable(str);
            List<Document> list = new List<Document>();
            foreach (DataRow item in table.Rows)
            {
                Document d = new Document();
                d.Document_Date = Convert.ToDateTime(item["Document_Date"]);
                d.Document_Id = Convert.ToInt32(item["Document_Id"]);
                d.Product_Id = Convert.ToInt32(item["Product_Id"]);
                d.Product_Name = item["Product_Name"].ToString();
                d.Document_Mate_Num = Convert.ToInt32(item["Document_Mate_Num"]);
                d.WareHose_Name = item["WareHose_Name"].ToString();
                d.Employee_Name = item["Employee_Name"].ToString();
                d.Document_Remark = item["Document_Remark"].ToString();
                d.Document_num = item["Document_num"].ToString();
                list.Add(d);
            }
            return list;
        }
    }
}
